package com.mm.cloth.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 衣物分类模型类
 * 对应服务器端的CategoryDTO
 */
public class Category implements Serializable {
    private Integer id;
    private Integer userId;
    private String name;
    private String iconUrl;  // 保持原有字段名，对应服务器的icon
    private Integer parentId;
    private Integer sortOrder;
    private Date createTime;
    private Date updateTime;
    private List<Category> children;  // 子分类列表

    public Category() {
        this.sortOrder = 0;
    }

    public Category(Integer id, String name) {
        this.id = id;
        this.name = name;
        this.sortOrder = 0;
    }

    public Category(Integer id, String name, String iconUrl) {
        this.id = id;
        this.name = name;
        this.iconUrl = iconUrl;
        this.sortOrder = 0;
    }

    public Category(Integer id, String name, String iconUrl, Integer parentId, Integer sortOrder) {
        this.id = id;
        this.name = name;
        this.iconUrl = iconUrl;
        this.parentId = parentId;
        this.sortOrder = sortOrder != null ? sortOrder : 0;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIconUrl() {
        return iconUrl;
    }

    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public List<Category> getChildren() {
        return children;
    }

    public void setChildren(List<Category> children) {
        this.children = children;
    }

    /**
     * 判断是否为顶级分类
     */
    public boolean isTopLevel() {
        return parentId == null || parentId == 0;
    }

    /**
     * 判断是否有子分类
     */
    public boolean hasChildren() {
        return children != null && !children.isEmpty();
    }

    @Override
    public String toString() {
        return "Category{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", iconUrl='" + iconUrl + '\'' +
                ", parentId=" + parentId +
                ", sortOrder=" + sortOrder +
                '}';
    }
}